package com.ctshk.sapp.order.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.tour.dto.custom.OrderBuyInsuranceDTO;
import com.ctshk.rpc.order.tour.dto.custom.OrderInsuranceDTO;
import com.ctshk.rpc.order.tour.dto.SeriesOrderCollectionCalculationDTO;
import com.ctshk.rpc.order.tour.dto.SeriesOrderCollectionListDTO;
import com.ctshk.rpc.order.tour.req.*;
import com.ctshk.rpc.order.tour.req.custom.*;
import com.ctshk.rpc.order.tour.service.ISeriesOrderCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系列团游客收款 前端控制器
 * </p>
 *
 * @author 谭响
 * @since 2021-01-18
 */
@Api(value="收款", tags="收款")
@RestController
@RequestMapping("/series/order/collection")
public class SeriesOrderCollectionController extends BaseController {

    @DubboReference
    private ISeriesOrderCollectionService iSeriesOrderCollectionService;



    @ApiOperation(value = "收款", notes = "收款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "收款管理-收款", operDesc = "收款管理-收款")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid CustomOrderCollectionAddReq req) {
        TokenUser currentUser = getCurrentUser(getRequest());
        return iSeriesOrderCollectionService.add(req,currentUser);
    }

    @ApiOperation(value = "银行优惠计算", notes = "计算（收款管理-收款-银行优惠计算）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "收款管理-收款-银行优惠计算", operDesc = "收款管理-收款-银行优惠计算")
    @PostMapping("/calculation")
    public Result<SeriesOrderCollectionCalculationDTO> calculation(@RequestBody @Valid SeriesOrderCollectionCalculationReq seriesOrderCollectionCalculationReq) {
        return iSeriesOrderCollectionService.calculation(seriesOrderCollectionCalculationReq, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "收款明细", notes = "列表（收款管理-收款明细）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收款管理-收款明细", operDesc = "收款管理-收款明细")
    @PostMapping("/list")
    public Result<List<SeriesOrderCollectionListDTO>> list(@RequestBody @Valid SeriesOrderTouristInfoDetailReq req) {
        return Result.success(iSeriesOrderCollectionService.list(req));
    }

    @ApiOperation(value = "再次確認", notes = "确认（收款管理-收款明細-再次確認）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "收款管理-收款明細-再次確認", operDesc = "收款管理-收款明細-再次確認")
    @PostMapping("/confirm")
    public Result confirm(@RequestBody @Valid SeriesOrderCollectionConfirmReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderCollectionService.confirm(req);
    }

    @ApiOperation(value = "可购买保险列表", notes = "可购买保险列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收款管理-购买保险", operDesc = "收款管理-购买保险")
    @PostMapping("/insurance-list")
    public Result<List<OrderInsuranceDTO>> insuranceList(@RequestBody @Valid CustomOrderInsuranceListReq req) {
        return iSeriesOrderCollectionService.insuranceList(req);
    }

    @ApiOperation(value = "購買保險", notes = "購買保險（收款管理-購買保險-購買）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "收款管理-購買保險-購買", operDesc = "收款管理-購買保險-購買")
    @PostMapping("/buy/insurance")
    public Result<OrderBuyInsuranceDTO> buyInsurance(@RequestBody @Valid CustomOrderBuyInsuranceReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderCollectionService.buyInsurance(req);
    }

    @ApiOperation(value = "保險收款", notes = "購買保險-保險收款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "購買保險-保險收款", operDesc = "購買保險-保險收款")
    @PostMapping("/collect-insurance")
    public Result collectInsurance(@RequestBody @Valid CustomOrderCollectInsuranceReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderCollectionService.collectInsurance(req);
    }

    @ApiOperation(value = "验证推广码", notes = "验证优惠（收款管理-使用优惠-驗證）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "收款管理-使用优惠-驗證", operDesc = "收款管理-使用优惠-驗證")
    @PostMapping("/verify/discount")
    public Result verifyDiscount(@RequestBody @Valid SeriesOrderCollectionVerifyDiscountReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderCollectionService.verifyDiscount(req);
    }

    @ApiOperation(value = "使用推广码", notes = "使用优惠（收款管理-使用优惠-兌換）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "收款管理-使用优惠-兌換", operDesc = "收款管理-使用优惠-兌換")
    @PostMapping("/use/discount")
    public Result useDiscount(@RequestBody @Valid SeriesOrderCollectionUseDiscountReq req) {
        return iSeriesOrderCollectionService.useDiscount(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "使用积分", notes = "使用积分（收款管理-使用積分-使用）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "收款管理-使用積分-使用", operDesc = "收款管理-使用積分-使用")
    @PostMapping("/use/points")
    public Result usePoints(@RequestBody @Valid SeriesOrderCollectionUsePointsReq req) {
        return iSeriesOrderCollectionService.usePoints(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "积分计算", notes = "使用积分计算（收款管理-使用積分）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "收款管理-使用積分", operDesc = "收款管理-使用積分")
    @PostMapping("/use/points/calculation")
    public Result usePointsCalculation(@RequestBody @Valid SeriesOrderCollectionUsePointsCalculationReq req) {
        return iSeriesOrderCollectionService.usePointsCalculation(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "调整项目", notes = "调整项目（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "收款管理-调整项目", operDesc = "收款管理-调整项目")
    @PostMapping("/adjust-project")
    public Result adjustProject(@RequestBody @Valid CustomOrderAdjustProjectReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderCollectionService.adjustProject(req);
    }

    @ApiOperation(value = "计算港币收款金额", notes = "保险收款-计算保险港币收款金额（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "保险收款-计算保险港币收款金额", operDesc = "保险收款-计算保险港币收款金额")
    @PostMapping("/get-hkd-amount")
    public Result getHkdAmount(@RequestBody @Valid List<GetHkdAmountReq> req) {
        return iSeriesOrderCollectionService.getHkdAmount(req);
    }

}
